<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="Content-Style-Type" content="text/css">
        <meta http-equiv="Content-Script-Type" content="text/javascript">

        <title>UI Tabs with close button example</title>

        <link rel="stylesheet" href="ui.tabs.css" type="text/css" media="print, projection, screen">
        <style type="text/css" media="screen, projection">

            /* close button */
            .ui-tabs-nav li {
                position: relative;
            }
            .ui-tabs-selected a span {
                padding-right: 10px;
            }
            .close {
                display: none;
                position: absolute;
                top: 8px;
                right: 7px;
                z-index: 2000;
                width: 14px;
                height: 13px;
                font-size: 10px;
                font-style: normal;
                cursor: pointer;
            }
            .ui-tabs-selected .close {
                display: block;
            }
            .close:hover {
                background: red;
            }

        </style>
        
        <script src="jquery-1.2.3.pack.js" type="text/javascript"></script>
        <script src="ui.tabs.pack.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                var $tabs = $('#container-1 ul').tabs({
                    add: function(ui) {
                        var li = $(ui.tab).parents('li:eq(0)')[0];
                        $('<em class="close" title="Close Tab">[x]</em>').appendTo(li)
                            .bind('click', function() {
                                //console.log( $('li', $tabs).index(li) );
                                $tabs.tabs('remove', $('li', $tabs).index(li));
                            });
                    }                  
                });
                    
                $('button').bind('click', function() {
                    $('#container-1 > ul').tabs('add', '#new', 'Close me');
                });
            });
        </script>
    </head>
    <body>
        <div id="container-1">
            <ul>
                <li><a href="#fragment-1"><span>Section 1</span></a></li>
                <li><a href="#fragment-2"><span>Section 2</span></a></li>
                <li><a href="#fragment-3"><span>Section 3</span></a></li>
            </ul>
            <div id="fragment-1">
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
            </div>
            <div id="fragment-2">
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
            </div>
            <div id="fragment-3">
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
            </div>
        </div>
        <p>
            <button type="button">Add tab</button>
        </p>
    </body>
</html>